<template>
	<view class="position-list-item" @tap="handleClickChange(item)">
		<view class="taskdetail-top">
			<!-- <view class="flex change" @tap.stop="handleClickChange(item)">
				<view class="change-img">
				<image class="img-c" src="../../static/icon/icon_edit.png" mode="widthFix" />
			</view>
				<view class="change-title">编辑</view>
			</view> -->
			<view class="taskdetail-box1 flex">
				<view class="flex flex-1 ccs">
					<view class="flex rcb">
						<view class="flex rcs">
							<h2 class="task-title">{{item.name}}</h2>
							<view class="task-post">【{{item.position_type.name}}】</view>
						</view>
						<view class="recu-money" :class="!item.status_name ? 'recu-money-cur' : null">{{item.status_name || '关闭中'}}</view>
					</view>
					<view class="task-todo">{{item.company_name_}}</view>
				</view>

				<view class="task-state" v-if="item.status_now">
					{{item.status_now}}
				</view>
			</view>
			<view class="taskdetail-box2">
				<view class="flex task-spe">
					<view class="task-numbox">
						<view class="task-num1">{{item.person_num}}</view>
						<view class="tast-titlenum">招聘数量</view>
					</view>
					<view class="task-numbox">
						<view class="task-num2">{{item.working}}</view>
						<view class="tast-titlenum">已招聘数量</view>
					</view>
					<view class="task-numbox">
						<view class="task-num1">{{item.age_lower}}-{{item.age_upper}}岁</view>
						<view class="tast-titlenum">招聘年龄</view>
					</view>
				</view>
				<view class="flex task-status">
					<view class="status-text">候选中: {{item.filter_num}}</view>
					<view class="status-text">体检中: {{item.phy_num}}</view>
					<view class="status-text">面试中: {{item.audition_num}}</view>
					<view class="status-text">待入职: {{item.wait_work}}</view>
				</view>
			</view>
			<!-- <view class="taskdetail-box3 flex">
				<view class="message-box">
					<view class="flex setmargin">
						<view class="message-title">学历:</view>
						<view class="message-content">{{item.edu_name_str}}</view>
					</view>
					<view class="flex">
						<view class="message-title">发布人:</view>
						<view class="message-content">{{item.username}}</view>
					</view>
				</view>
				<view class="message-box">
					<view class="flex setmargin">
						<view class="message-title">性别:</view>
						<view class="message-content">{{item.sex_desc}}</view>
					</view>
					<view class="flex">
						<view class="message-title">结束日期:</view>
						<view class="message-content">{{item.end_date}}</view>
					</view>
				</view>
			</view> -->
		</view>
		<view class="taskdetail-bottom flex">
			<view class="add-border flex rcc" v-if="item.status != 0" @tap.stop="handleClickClose(item)">
				<view class="img-box">
					<image src="../../static/icon/icon_user_recommend.png" class="img" mode="widthFix" />
				</view>
				<view class="img-title">关闭岗位</view>
			</view>
			<view class="add-border flex rcc" v-if="item.status == 0" @tap.stop="handleClickOpen(item)">
				<view class="img-box">
					<image src="../../static/icon/icon_user_recommend.png" class="img" mode="widthFix" />
				</view>
				<view class="img-title">开启岗位</view>
			</view>
			<view class="add-border flex rcc" @tap.stop="handleClickQrcode(item)">
				<view class="img-box">
					<image src="../../static/icon/icon_qr_code.png" class="img" mode="widthFix" />
				</view>
				<view class="img-title">招聘海报</view>
			</view>
			<view class="add-border flex rcc" @tap.stop="handleClickMate(item)">
				<view class="img-box">
					<image src="../../static/icon/icon_user_plus.png" class="img" mode="widthFix" />
				</view>
				<view class="img-title">智能匹配</view>
			</view>
			<view class="add-border flex rcc del-border" @tap.stop="handleClickRecruit(item)">
				<view class="img-box">
					<image src="../../static/icon/icon_present.png" class="img" mode="widthFix" />
				</view>
				<view class="img-title">招聘情况</view>
			</view>
		</view>
	</view>
</template>

<script scoped>
	export default {
		components: {

		},
		props: {
			item: Object,
			index: Number,
			onRefresh: Function,
		},
		data() {
			return {
				token: '',
			}
		},
		methods: {

			// 取token
			getToken() {
				try {
					const value = uni.getStorageSync('login_key');
					if (value) {
						this.token = value;
					}
				} catch (e) {
					// error
				}
			},
			// 点击招聘情况
			handleClickRecruit(items) {
				// console.log(items.position_type.id)
				// let position_id = items.position_type.id
				let position_id = items.id
				uni.navigateTo({
					url: '/pages/talent_pool/my_talent_list?position_id=' + position_id
				})
			},
			// 点击智能匹配
			handleClickMate(items) {
				let item = encodeURIComponent(JSON.stringify(items));
				// console.log('item---->', item);
				uni.navigateTo({
					url: '/pages/work_bench/recommendList?items=' + item
				})
			},
			// 点击二维码
			async handleClickQrcode(items) {
				this.getToken()
				let itemList = JSON.stringify(items);

				uni.navigateTo({
					url: '/pages/recruitment/recruitment_qrcode?items=' + encodeURIComponent(itemList)
				})
			},
			// 点击关闭
			async handleClickClose(items) {
				// console.log('this.onRefresh---->', this.onRefresh);
				this.getToken()
				// 发请求
				let url = this.ServicesApi.positionSetInvalid;
				let data = {
					id: items.id,
					status: 0,
				};
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					// console.log('禁用',res.data)
					this.onRefresh && this.onRefresh();
					uni.showToast({
						icon: 'none',
				        title: result.msg
					})
				}
				// uni.request({
				// 	url: this.ServicesApi.positionSetInvalid,
				// 	method: 'POST',
				// 	header: {
				// 		"content-type": "application/x-www-form-urlencoded"
				// 	},
				// 	data: {
				// 		token: this.token,
				// 		id: items.id,
				// 		status: 0,
				// 	},
				// 	success: (res) => {
				// 		// console.log('禁用',res.data)
				// 		this.onRefresh && this.onRefresh();
				// 		uni.showToast({
				// 			title: res.data.msg
				// 		})
				// 	}
				// });
			},
			// 点击开启
			async handleClickOpen(items) {
				this.getToken()
				// 发请求
				let url = this.ServicesApi.positionSetInvalid;
				let data = {
					id: items.id,
					status: 1,
				};
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					// console.log('企用',res.data)
					this.onRefresh && this.onRefresh();
					uni.showToast({
						icon: 'none',
				        title: result.msg
					})
				}
				// uni.request({
				// 	url: this.ServicesApi.positionSetInvalid,
				// 	method: 'POST',
				// 	header: {
				// 		"content-type": "application/x-www-form-urlencoded"
				// 	},
				// 	data: {
				// 		token: this.token,
				// 		id: items.id,
				// 		status: 1,
				// 	},
				// 	success: (res) => {
				// 		// console.log('企用',res.data)
				// 		this.onRefresh && this.onRefresh();
				// 		uni.showToast({
				// 			title: res.data.msg
				// 		})
				// 	}
				// });
			},
			// 点击编辑跳转页面并传参
			async handleClickChange(items) {
				this.getToken()
				let item = encodeURIComponent(JSON.stringify(items));
				let url = this.ServicesApi.getPositionDetail;
				let data = {
					id: items.id,
				};
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					let subsidy = encodeURIComponent(JSON.stringify(result.data.subsidy));
					console.log('subsidy---->', subsidy);
					uni.navigateTo({
						url: "/pages/publish/addRecruitmentPosition?item=" + item + "&subsidy=" + subsidy
					})
				}
				// uni.request({
				// 	url: this.ServicesApi.getPositionDetail,
				// 	method: 'POST',
				// 	header: {
				// 		"content-type": "application/x-www-form-urlencoded"
				// 	},
				// 	data: {
				// 		token: this.token,
				// 		id: items.id,
				// 	},
				// 	success: (res) => {
				// 		let subsidy = JSON.stringify(res.data.data.subsidy)
				// 		console.log('subsidy---->', subsidy);
				// 		uni.navigateTo({
				// 			url: "/pages/publish/addRecruitmentPosition?item=" + item + "&subsidy=" + subsidy
				// 		})
				// 	}
				// });
				// console.log('要传的参数',items)
			}
		},
		mounted() {
			this.getToken()
		}
	}
</script>

<style scoped lang="stylus">
	.position-list-item {
		margin-top: 20rpx;
	}

	.taskdetail-top {
		padding: 30rpx 30rpx 0;
		background: #fff;

		.change {
			align-items: center;
			float: right;

			.change-img {
				height: 38upx;
				width: 38upx;

				.img-c {
					height: 38upx;
					width: 38upx;
				}
			}

			.change-title {
				font-size: 28upx;
				color: #333333;
			}
		}

		.taskdetail-box1 {
			align-items: center;
			justify-content: space-between;

			.task-title {
				font-size: 40upx;
				font-weight: 500;
				color: #333;
			}

			.recu-money {
				height: 34upx;
				width: 96upx;
				border: 1upx solid #5BBD00;
				line-height: 34upx;
				text-align: center;
				font-size: 22upx;
				color: #5BBD00;
			}

			.recu-money-cur {
				color: #f00;
				border-color: #f00;
			}

			.task-todo {
				color: #666;
				font-size: 28rpx;
				margin-top: 20rpx;
			}

			.task-post {
				font-size: 28upx;
				color: #666666;
			}

			.task-state {
				height: 46upx;
				width: 144upx;
				border: 1upx solid #5BBD00;
				font-size: 28upx;
				color: #5BBD00;
				font-weight: 500;
				line-height: 46upx;
				text-align: center;
			}
		}

		.taskdetail-box2 {
			background: linear-gradient(270deg, rgba(250, 250, 250, 1) 0%, rgba(243, 243, 243, 1) 100%);
			padding: 30rpx 0;
			margin-top: 20rpx;

			.task-spe {
				margin-bottom: 20rpx;
				justify-content: space-around;
			}

			.task-numbox {
				text-align: center;

				.task-num1 {
					font-size: 36upx;
					font-weight: 500;
					color: #333;
				}

				.task-num2 {
					font-size: 36upx;
					color: #4A90E2;
					font-weight: 500;
				}

				.tast-titlenum {
					font-size: 28upx;
					color: #666;
				}
			}

			.task-status {
				justify-content: space-around;

				.status-text {
					font-size: 28upx;
					color: #999999;
				}
			}
		}

		.taskdetail-box3 {
			margin: 20upx 0;

			.message-box {
				flex: 1;

				.setmargin {
					margin-bottom: 30upx;
				}

				.message-title {
					font-size: 28upx;
					color: #999999;
				}

				.message-content {
					font-size: 28upx;
					color: #333333;
					margin-left: 12upx;
				}
			}
		}
	}

	.taskdetail-bottom {
		align-items: center;
		justify-content: space-around;
		align-items: center;
		background: #fff;
		// border-top: 2rpx solid #DBDBDB;

		.add-border {
			flex: 1;
			border-right: 1upx solid #DBDBDB;
			margin: 16upx auto;
			text-align: center;

			// padding:0 38upx;
			.img-box {
				height: 26upx;
				width: 26upx;
				align: center;
				// margin: 0 auto;
				margin-right: 12rpx;

				.img {
					height: 26upx;
					// margin-bottom: 8upx;
					width: 26upx;
				}
			}

			.img-title {
				font-size: 26upx;
				color: #333;
				// margin-top: 10upx;
			}
		}

		.del-border {
			border: 0;
		}
	}
</style>
